<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>

<!DOCTYPE html>

<html>
<head>
	<meta charset="utf-8" />
	<title>도서 등록</title>
	<link rel="Stylesheet" href="/libweb/styles/default.css" />
	<link rel="Stylesheet" href="/libweb/styles/input.css" />
	<script type="text/javascript">
		function checkAndSubmit() {
			var message = "";
			
			var title = document.getElementById("title");
			if (title.value.length == 0) {
				message += "제목을 입력하세요.\r\n";
			}
			
			var publisher = document.getElementById("publisher");
			if (publisher.value.length == 0) {
				message += "출판사를 입력하세요.\r\n";
			}
			
			var author = document.getElementById("author");
			if (author.value.length == 0) {
				message += "저자를 입력하세요.\r\n";
			}
			
			var pubdate = document.getElementById("pubdate");
			if (pubdate.value.length == 0) {
				message += "출간일를 입력하세요.\r\n";
			}
			
			var re = /^[0-9]{8,8}$/;
			if(!re.test(pubdate.value)) {
				message += "출간일 형식 오류 (YYYYMMDD)\r\n";
			}
			
			if (message.length > 0) {
				alert(message);
			} else {
				document.getElementById("registerform").submit();
			}
		}
	</script>
</head>
<body>

	<div id="pageContainer">
	
		<% pageContext.include("/WEB-INF/views/include/header.jsp"); %>
		
		<div id="inputcontent">
			<br /><br />
		    <div id="inputmain">
		        <div class="inputsubtitle">도서 정보</div>

		        <form id="registerform" action="register.action" method="post"><!-- 상대경로표시 -->
			        <table>
			            <tr>
			                <th>제목</th>
			                <td>
			                    <input type="text" id="title" name="title" style="width:280px" />
			                </td>
			            </tr>
			            <tr>
			                <th>출판사</th>
			                <td>
			                	<input type="text" id="publisher" name="publisher" style="width:280px" />
			                </td>
			            </tr>
			            <tr>
			                <th>저자</th>
			                <td>
			                    <input type="text" id="author" name="author" style="width:280px" />
			                </td>
			            </tr>
			            <tr>
			                <th>출간일(YYYYMMDD)</th>
			                <td>
			                	<input type="text" id="pubdate" name="pubdate" style="width:280px" />
			                </td>
			            </tr>		            		            
			        </table>
			        <div class="buttons">
			        	<input type="button" value="등록" style="height:25px" onclick="checkAndSubmit();" />
			        	<input type="button" value="취소" style="height:25px"
			        		onclick="location.href='list.action';" />
			        </div>
		        </form>
		    </div>
		</div>	
	</div>
</body>
</html>